<?php
/**
 * 插件展示页面
 * 访问 index.php?plugin=插件名
 * 会自动加载此文件
 */
if (!defined('SYSTEM_ROOT')) { die('Insufficient Permissions'); } 
loadhead();
?>
<div class="" id="newid" style="">
<script type="text/javascript" src="./plugins/bbaa_baiduid/base.js"></script>
<div id="addbdid_prog" style="display:block">
  <b><span class="addbdis_text"></span></b><br/><br/>
  <div class="progress" style="display:none;">
    <div class="progress-bar progress-bar-striped active" id="addbdid_pb" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width: 25%">
    </div>
  </div>
</div>
<div class="alert alert-warning" role="alert" id="addbdid_msg">如果您多次尝试绑定失败，可能是异地登录保护造成的原因，不妨试试 <a href="https://bduss.tbsign.cn" target="_blank">手动获取</a> 吧！</div>
<form method="post" id="addbdid_form" onsubmit="return false;">
<div class="input-group">
  <span class="input-group-addon">百度账号</span>
  <input type="text" class="form-control" id="bd_name" placeholder="你的百度账户名，建议填写邮箱" required>
</div>

<br/>

<div class="input-group">
  <span class="input-group-addon">百度密码</span>
  <input type="password" class="form-control" id="bd_pw" placeholder="你的百度账号密码" required>
</div>
<br/>
  <div id="addbdid_ver" style="display: none">
    &nbsp;&nbsp;&nbsp;请在下面输入的字符<br>&nbsp;&nbsp;&nbsp;点击图片更换验证码
    <br/><br/>
	<div id="codeimg"></div>
    <div class="input-group">
      <span class="input-group-addon">验证码</span>
       <input type="text" class="form-control" id="bd_v" placeholder="请输入上图的字符" />
    </div>
    <br/>
    <input type="hidden" id="vcodeStr" name="vcodestr" value=""/>
      <input type="hidden" id="addbdid_vcodeRequired" value="0">
  </div>
  	<div id="security" class="input-group" style="display:none;">
		<td>
			<div class="input-group">
			<span class="input-group-addon">验证码</span>
			<input type="text" id="smscode" value="" class="form-control">
			<span class="input-group-btn">
			<button id="sendcode" class="btn btn-default" type="button">发送验证码</button>
			</span>
			</div>
		</td>
	<button type="button" id="submit2" class="btn btn-primary btn-block">提交</button>
		<pre>提示：60秒内只能发送一次验证码，否则会提示频繁</pre>
	</div>
<input type="submit" id="addbdid_submit" class="btn btn-primary" value="点击绑定">
</form>
<br/><br/>
<div class="panel panel-default">
	<div class="panel-heading" onclick="$('#win_bduss').fadeToggle();"><h3 class="panel-title"><span class="glyphicon glyphicon-chevron-down"></span> 关于提示登陆不成功的解决办法</h3></div>
	<div class="panel-body" id="win_bduss">
	    1.<b>登录不成功主要是因为您尝试登录的帐号开启了异地登陆保护！</b>
	    <br/><br/>2.所以我们试着关闭它，地址:<a href="https://passport.baidu.com/v2/accountsecurity" target="_blank">点击进入百度安全中心</a> （未登录百度请先登录再打开此链接）
	    <br/><br/>3.此时可以看到 <b>登录保护：未开通</b> 然后我们点击后面的开通，然后选择 <b>每次主动登录时需要验证安全中心手机版、短信或邮件验证码，三者任选其一</b> 然后点击确定提示验证，验证后提示设置成功。
        <br/><br/>4.然后返回 <a href="https://passport.baidu.com/v2/accountsecurity" target="_blank">百度安全中心</a> 可以看到 <b>登录保护：登录即启动保护</b> 然后我们点后面的 <b>修改</b> 。
        <br/><br/>5.最后，我们可以看到一个之前看不到的选项 <b>关闭登录保护</b> 选择它确定，直到提示成功后，然后再次在上面自动绑定处尝试进行登录，登陆成功后刷新贴吧列表即可！
	</div>
</div>
</div>
<script>
var ajax={
	get: function(url, dataType, callback) {
		dataType = dataType || 'html';
		$.ajax({
			type: "GET",
			url: url,
			async: true,
			dataType: dataType,
			cache:false,
			success: function(data,status) {
				if (callback == null) {
					return;
				}
				callback(data);
			},
			error: function(error) {
				alert('创建连接失败');
			}
		});
	},
	post: function(url, parameter, dataType, callback) {
		dataType = dataType || 'html';
		$.ajax({
			type: "POST",
			url: url,
			async: true,
			dataType: dataType,
			data: parameter,
			cache:false,
			success: function(data,status) {
				if (callback == null) {
					return;
				}
				callback(data);
			},
			error: function(error) {
				alert('创建连接失败');
			}
		});
	}
}
function trim(str){ //去掉头尾空格
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function getpwd(pwd,time){
	var passwd = pwd+time;
	var rsa = "B3C61EBBA4659C4CE3639287EE871F1F48F7930EA977991C7AFE3CC442FEA49643212E7D570C853F368065CC57A2014666DA8AE7D493FD47D171C0D894EEE3ED7F99F6798B7FFD7B5873227038AD23E3197631A8CB642213B9F27D4901AB0D92BFA27542AE890855396ED92775255C977F5C302F1E7ED4B1E369C12CB6B1822F";
	setMaxDigits(131);
	var key = new RSAKeyPair("10001", "", rsa);
	return encryptedString(key, passwd);
}
function gettime(user,pwd,vcode,vcodestr){
	vcode=vcode||null;
	vcodestr=vcodestr||null;
	$('.addbdis_text').html('正在获取Token，请稍等...');
	var getvcurl="./plugins/bbaa_baiduid/bbaa_baiduid_ajax.php?do=time";
	ajax.get(getvcurl, 'json', function(d) {
		if(d.code ==0){
			login(d.time,user,pwd,vcode,vcodestr);
		}else{
			alert(d.msg);
			$('.addbdis_text').html('');
		}
	});
}
function login(time,user,pwd,vcode,vcodestr){
	$('.addbdis_text').html('正在登录，请稍等...');
	var p = getpwd(pwd, time);
	//alert(p);return;
	var loginurl="./plugins/bbaa_baiduid/bbaa_baiduid_ajax.php?do=login";
	ajax.post(loginurl,"time="+time+"&user="+user+"&pwd="+pwd+"&p="+p+"&vcode="+vcode+"&vcodestr="+vcodestr+"&r="+Math.random(1), 'json', function(d) {
		if(d.code ==0){
			////$('#login').hide();
			$('#addbdid_ver').hide();
			$('#addbdid_form').hide();
			$('#security').hide();
			$('#submit2').hide();
			$('.addbdis_text').html('登录成功！id:'+decodeURIComponent(d.displayname));
			//showresult(d);
		}else if(d.code ==400023){
			if(d.type == 'phone'){
				$('.addbdis_text').html("请验证密保后登录，密保手机是："+d.phone);
			}else{
				$('.addbdis_text').html("请验证密保后登录，密保邮箱是："+d.email);
			}
			//$('#addbdid_form').hide();
			$('#addbdid_ver').hide();
			$('#bd_v').val("");
			$('#security').show();$('#addbdid_submit').hide();
			$('#security').attr('type',d.type);
			$('#security').attr('lstr',encodeURIComponent(d.lstr));
			$('#security').attr('ltoken',d.ltoken);
		}else if(d.code ==310006 || d.code ==500001 || d.code ==500002){//需要验证码
			$('.addbdis_text').html(d.msg);
			getvc(d.vcodestr);
		}else if(d.code ==230048 || d.code ==400010){
			$('.addbdis_text').html("您输入的账号不存在，请重新输入");
			$('#addbdid_form').attr('do','submit');
			$('#addbdid_ver').hide();
			$('#bd_v').val("");
			$('#bd_name').focus();
			$('#bd_name').val("");
		}else if(d.code ==400011 || d.code ==400015){
			$('.addbdis_text').html("您输入的密码有误，请重新输入");
			$('#addbdid_form').attr('do','submit');
			$('#addbdid_ver').hide();
			$('#bd_v').val("");
			$('#bd_pw').focus();
			$('#bd_pw').val("");
		}else{
			$('.addbdis_text').html(d.msg+" ("+d.code+")");
			$('#addbdid_form').attr('do','submit');
			$('#addbdid_ver').hide();
			//$('#login').show();
		}
	});
	
}
function login2(type,lstr,ltoken,vcode){
	$('.addbdis_text').html('正在登录，请稍等...');
	var loginurl="./plugins/bbaa_baiduid/bbaa_baiduid_ajax.php?do=login2";
	ajax.post(loginurl,"type="+type+"&lstr="+lstr+"&ltoken="+ltoken+"&vcode="+vcode+"&r="+Math.random(1), 'json', function(d) {
		if(d.code ==0){
			$('.addbdis_text').html('登录成功！id:'+decodeURIComponent(d.displayname));
			//$('#login').hide();
			$('#addbdid_ver').hide();
			$('#addbdid_form').show();
			$('#security').hide();
			$('#submit2').hide();
			//showresult(d);
		}else{
			$('.addbdis_text').html(d.msg+" ("+d.code+")");
			$('#addbdid_ver').hide();
			//$('#login').show();
		}
	});
	
}
function sendcode(type,lstr,ltoken){
	var loginurl="./plugins/bbaa_baiduid/bbaa_baiduid_ajax.php?do=sendcode";
	ajax.post(loginurl,"type="+type+"&lstr="+lstr+"&ltoken="+ltoken+"&r="+Math.random(1), 'json', function(d) {
		if(d.code ==0){
			$('#addbdid_ver').hide();
			$('#smscode').focus();
			alert('验证码发送成功，请查收');
		}else{
			$('#addbdid_ver').hide();
			alert(d.msg);
		}
	});
	
}
function getvc(vcodestr){
	$('#codeimg').attr('vcodestr',vcodestr);
	$('#codeimg').html('<img onclick="this.src=\'./plugins/bbaa_baiduid/bbaa_baiduid_ajax.php?do=getvcpic&vcodestr='+vcodestr+'&r=\'+Math.random();" src="./plugins/bbaa_baiduid/bbaa_baiduid_ajax.php?do=getvcpic&vcodestr='+vcodestr+'&r='+Math.random(1)+'" title="点击刷新">');
	$('#addbdid_form').attr('do','code');
	$('#bd_v').val("");
	$('#addbdid_ver').show();
}
function checkvc(user,pwd){
	$('.addbdis_text').html('登录中，请稍候...');
	var getvcurl="./plugins/bbaa_baiduid/bbaa_baiduid_ajax.php?do=checkvc";
	ajax.post(getvcurl, 'user='+user, 'json', function(d) {
		if(d.code ==0){
			gettime(user,pwd);
		}else if(d.code ==1){
			$('.addbdis_text').html('请输入验证码。');
			getvc(d.vcodestr);
		}else{
			$('.addbdis_text').html(d.msg+" ("+d.code+")");
			$('#addbdid_ver').hide();
		}
	});
}
$(document).ready(function(){
	$('#addbdid_form').submit(function(){
		var self=$(this);
		var user=trim($('#bd_name').val()),
			pwd=trim($('#bd_pw').val());
		if(user==''||pwd=='') {
			alert("请确保每项不能为空！");
			return false;
		}
		$('.addbdis_text').show();
		if (self.attr("data-lock") === "true") return;
		else self.attr("data-lock", "true");
		if(self.attr('do') == 'code'){
			var vcode=trim($('#bd_v').val()),
				vcodestr=$('#codeimg').attr('vcodestr');
			gettime(user,pwd,vcode,vcodestr);
		}else{
			checkvc(user,pwd);
		}
		self.attr("data-lock", "false");
	});
	$('#submit2').click(function(){
		var self=$(this);
		var code=trim($('#smscode').val());
		if(code=='') {
			alert("验证码不能为空！");
			return false;
		}
		$('.addbdis_text').show();
		if (self.attr("data-lock") === "true") return;
		else self.attr("data-lock", "true");
		var type=$('#security').attr('type'),
			lstr=$('#security').attr('lstr'),
			ltoken=$('#security').attr('ltoken');
		login2(type,lstr,ltoken,code);
		selpf.attr("data-lock", "false");
	});
	$('#sendcode').click(function(){
		var self=$(this);
		$('.addbdis_text').show();
		if (self.attr("data-lock") === "true") return;
		else self.attr("data-lock", "true");
		var type=$('#security').attr('type'),
			lstr=$('#security').attr('lstr'),
			ltoken=$('#security').attr('ltoken');
		sendcode(type,lstr,ltoken);
		self.attr("data-lock", "false");
	});
});
</script>
<?php loadfoot(); ?>